package com.example.srtestapplication;

import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class WelcomeActivity extends AppCompatActivity implements View.OnClickListener {

    private TextView count_down_view;
    private CountDownTimer countDownTimer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        count_down_view = findViewById(R.id.count_down_view);
        count_down_view.setOnClickListener(this);
        startCountdown();
    }


    private void startCountdown() {
        // 设置倒计时的总时长（单位：毫秒）和倒计时的间隔（单位：毫秒）
        // 这里设置总时长为 60 秒，间隔为 1 秒
        countDownTimer = new CountDownTimer(5000, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {
                // 每次倒计时间隔触发此方法，更新倒计时显示
                int seconds = (int) (millisUntilFinished / 1000);
                count_down_view.setText("跳过" + seconds);
            }

            @Override
            public void onFinish() {
                // 倒计时结束时触发此方法
                intentToLogin();
            }
        }.start();
    }

    private void intentToLogin() {
        Intent intent = new Intent(WelcomeActivity.this, LoginActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        startActivity(intent);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.count_down_view) {
            intentToLogin();
            countDownTimer.cancel();
        }
    }

}